package com.millstein.eduservice.controller;


import com.millstein.commonutils.Result;
import com.millstein.eduservice.entity.subject.OneSubject;
import com.millstein.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-13
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    /**
     * 批量添加课程分类
     * @param file
     * @return
     */
    @PostMapping("addSubject")
    public Result addSubject(MultipartFile file) {
        eduSubjectService.saveSubject(file, eduSubjectService);
        return Result.ok();
    }

    /**
     * 获取所有的课程分类，返回格式是树形结构
     * @return
     */
    @GetMapping("getAllSubject")
    public Result getAllSubject() {
        List<OneSubject> list = eduSubjectService.getAllOneTwoSubject();
        return Result.ok().data("list", list);
    }

}

